import javax.xml.catalog.Catalog;

public class TestAnimal {

    public static void main1(String[] args) {
        Dog dog1 = new Dog("旺财", 3);
        Fish fish1 = new Fish("六六", 2);
//        Animal animal = dog1;
//        animal.eat();
//        eat(fish1);
        Dog dog2 = (Dog) buyAnimal("狗");
        dog2.bark();
        Animal animal1 = buyAnimal("鱼");
        animal1.eat();
    }

    public static void eat(Animal animal) {
        animal.eat();
    }

    public static Animal buyAnimal(String a) {
        if(a.equals("狗")) {
            return new Dog("狗狗", 1);
        } else if(a.equals("鱼")) {
            return new Fish("小鱼", 1);
        } else {
            return null;
        }
    }

    public static void main2(String[] args) {
        Fish fish1 = new Fish("元宝", 2);
        Dog dog1 = new Dog("小七", 1);

        Animal animal = fish1;
        animal.eat();
        animal = dog1;
        animal.eat();

        if(animal instanceof Fish) {
            fish1 = (Fish) animal;
            fish1.wuwu();
        }

        if(animal instanceof Dog) {
            dog1 = (Dog) animal;
            dog1.bark();
        }
    }

    public static void main3(String[] args) {
        Dog dog1 = new Dog("小七", 1);
        Fish fish1 = new Fish("元宝", 2);
        eat1(dog1);
        eat1(fish1);
        Animal animal = dog1;

        if(animal instanceof Dog) {
            Dog dog2 = (Dog) animal;
            dog2.bark();
        }

        if(animal instanceof Fish) {
            Fish fish2 = (Fish) animal;
            fish2.wuwu();
        }

    }

    public static void eat1(Animal animal) {
        animal.eat();
    }

    public static void main4(String[] args) {
        Dog dog1 = new Dog("小七", 1);
        Fish fish1 = new Fish("元宝", 2);

        Animal animal1 = dog1;
        Animal animal2 = fish1;

        animal1.eat();
        animal2.eat();

        dog1.eat();
        fish1.eat();

        dog1.bark();
        fish1.wuwu();
    }

    public static void main33(String[] args) {
        Animal animal1 = new Dog("小七", 1);
        Animal animal2 = new Fish("元宝", 2);
        animal1.eat();
        animal2.eat();
        Dog dog1 = (Dog) animal1;
        Fish fish1 = (Fish) animal2;
        fish1.wuwu();
        dog1.bark();
//        Dog dog2 = (Dog) animal2;
//        dog2.bark();
    }

    public static void main(String[] args) {
        Dog dog1 = new Dog("小七", 1);
        Fish fish1 = new Fish("元宝", 2);

        Animal animal1 = dog1;
        Animal animal2 = fish1;
        dog1.eat();
        fish1.eat();

        if(animal1 instanceof Dog) {
            Dog dog2 = (Dog) animal1;
            dog2.bark();
            dog2.eat();
        }

        if(animal2 instanceof Fish) {
            Fish fish2 = (Fish) animal2;
            fish2.wuwu();
            fish1.eat();
        }
    }

}
